import React from 'react';
import { Route, Switch, Redirect } from 'react-router-dom';
import PropTypes from 'prop-types';
let ViewsRouter = (props) => {
  return (
    <React.Suspense fallback={'loading'}>
      <Switch>
        (
        {props.router.map((item) => {
          return item.component ? (
            <Route
              key={item.id}
              exact={item.isExact}
              path={item.path}
              component={(props) => {
                return <item.component {...props} router={item.children}></item.component>;
              }}
            ></Route>
          ) : (
            <Redirect
              key={item.id}
              exact={item.isExact}
              from={item.path}
              to={item.redirect}
            ></Redirect>
          );
        })}
        )
      </Switch>
    </React.Suspense>
  );
};
ViewsRouter.propTypes = {
  router: PropTypes.arrayOf(PropTypes.object),
};
export default ViewsRouter;
